/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers.pipes;

import java.util.NoSuchElementException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 *
 * @author Sergio
 */
public final class Validator2PersistencePipe {
  private BlockingQueue<String> theQueue = new LinkedBlockingQueue<>();
  private static Validator2PersistencePipe instance = null;
  private Validator2PersistencePipe() {
    //does not do anything
  }
  public String getElement() {
    try {
      String word = theQueue.remove();
      return word;
    } catch (NoSuchElementException crap) {
      return null;
    }
  }
  public void insertInto(String element) throws InterruptedException {
//    for (String ww : theQueue){
//      System.out.println("{"+ww+"}");
//    }
    
    theQueue.add(element);
  }
  public static Validator2PersistencePipe getInstance() {
    if (instance == null) {
      System.out.println("Initialazing process queue...");
      instance = new Validator2PersistencePipe();
    }
    return instance;
  }
}
